package homework.api03;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo {
    public static void main(String[] args) {
        //
        Collection collection = new ArrayList();
        collection.add(new Point(1,2));
        collection.add(new Point(3,4));
        collection.add(new Point(5,6));
        Point point = new Point(10,11);
        collection.add(point);
        System.out.println("point是否存在："+collection.contains(point));
        System.out.println(collection.add(new Point(7,8)));////添加方法返回true
        System.out.println(collection);
        System.out.println(collection.size());//查询元素个数 5
        System.out.println(collection.remove(point));//删除 返回true
        System.out.println("collection:"+collection);
        Collection collection1 = new ArrayList();
        collection1.add(new Point(20,20));
        collection1.add("随便");
        collection1.add(1);
        collection1.add(new Point(1,2));
        collection1.add(new Point(3,4));
        //System.out.println(collection.removeAll(collection1)); //去除交集
        // System.out.println(collection);
        //System.out.println(collection.retainAll(collection1));//保留交集
       // System.out.println(collection);
        //collection.clear();//清空
        //System.out.println(collection);
        //System.out.println("是否为空："+collection.isEmpty());//是否为空
        System.out.println("collection1:"+collection1);
        collection.addAll(collection1);
        System.out.println("collection:"+collection);
        Iterator it = collection.iterator();
        System.out.println(collection.containsAll(collection1));
        while (it.hasNext()){
            System.out.println(it.next());
        }
    }
}
